import testPanelView from "../view/testPanelview";
import { itemData, testPanelmodel } from "../../model/testPanelmodel";

const {ccclass, property} = cc._decorator;

@ccclass
export default class testPanelcontroller extends cc.Component {
    @property(testPanelView)
    view: testPanelView = null;
    model:testPanelmodel = testPanelmodel.instance();

    onLoad()
    {
        this.model.initData();
        this.view.init();
        this.view.set_title(this.model.title);
        this.view.set_scrollView(this.model.itemDataList);
    }

    onClickAdd()
    {
        let data:itemData = 
        {
            name:"添加xx",
            value1: Math.floor(Math.random() * Math.floor(1000)),
            value2:2,
            value3:3,
        }
        this.model.add_Item(data);
        this.updateView();
    }

    updateView()
    {
        this.view.clearAll_Item();
        this.view.set_scrollView(this.model.itemDataList);
    }
}
